<template>
  <el-dialog
    title="修改课程顾问"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
    <el-form-item label="学员姓名" prop="studentId">
      <el-select v-model="dataForm.studentId" filterable placeholder="学员姓名">
          <el-option
            v-for="item in studentList"
            :key="item.id"
            :label="item.studentName"
            :value="item.id">
          </el-option>
        </el-select>
    </el-form-item>
    <!-- <el-form-item label="学员阶段" prop="studentStage">
      <el-select v-model="dataForm.studentStage" placeholder="学员阶段">
        <el-option v-for="(item, index) in studentStagePtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item> -->
    <!-- <el-form-item label="课程顾问" prop="consultant" v-if="dataForm.id">
      <el-input v-model="dataForm.consultant" placeholder="课程顾问"></el-input>
    </el-form-item> -->
    <!-- <el-form-item label="试听意向度" prop="listeningIntentionality">
      <el-select v-model="dataForm.listeningIntentionality" placeholder="试听意向度">
        <el-option v-for="(item, index) in listeningIntentionalityPtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="来源渠道" prop="sourceChannel">
      <el-select v-model="dataForm.sourceChannel" placeholder="来源渠道">
        <el-option v-for="(item, index) in sourceChannelPtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="跟进状态" prop="followStatus">
      <el-select v-model="dataForm.followStatus" placeholder="跟进状态">
        <el-option v-for="(item, index) in followStatusPtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="上次跟进时间" prop="followTime">
      <el-date-picker
            v-model="dataForm.followTime"
            type="datetime"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="课堂状态" prop="classroomStatus">
      <el-select v-model="dataForm.classroomStatus" placeholder="课堂状态">
        <el-option v-for="(item, index) in classroomPtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="考勤状态" prop="attendanceStatus">
      <el-select v-model="dataForm.attendanceStatus" placeholder="考勤状态" style="width:150px;height:50px">
        <el-option v-for="(item, index) in attendancePtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="是否退订" prop="isUnsubscribe">
     <el-select v-model="dataForm.isUnsubscribe" placeholder="是否退订" style="width:150px;height:50px">
       <el-option v-for="(item, index) in isUnsubscribePtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
     </el-select>
    </el-form-item>
    <el-form-item label="试听时间" prop="auditionTime">
      <el-date-picker
            v-model="dataForm.auditionTime"
            type="datetime"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="预约人" prop="appointmentPerson">
      <el-input v-model="dataForm.appointmentPerson" placeholder="预约人"></el-input>
    </el-form-item>
    <el-form-item label="预约时间" prop="appointmentTime">
      <el-date-picker
            v-model="dataForm.appointmentTime"
            type="datetime"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="报名意向度" prop="registrationIntention">
      <el-select v-model="dataForm.registrationIntention" placeholder="试听意向度">
        <el-option v-for="(item, index) in listeningIntentionalityPtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="学员类型" prop="studentType">
      <el-select v-model="dataForm.studentType" placeholder="学员类型" style="width:150px;height:50px">
        <el-option v-for="(item, index) in studentTypePtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="学员状态" prop="studentStatus">
      <el-select v-model="dataForm.studentStatus" placeholder="学员状态" style="width:150px;height:50px">
        <el-option v-for="(item, index) in studentStatusPtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item>-->
    <el-form-item label="辅导老师" prop="coachTeacher">
      <el-input v-model="dataForm.coachTeacher" placeholder="辅导老师"></el-input>
    </el-form-item>
    <!-- <el-form-item label="续费意向度" prop="renewalIntention">
      <el-select v-model="dataForm.renewalIntention" placeholder="续费意向度" style="width:150px;height:50px">
        <el-option v-for="(item, index) in listeningIntentionalityPtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="转介绍意向度" prop="introductionIntention">
      <el-select v-model="dataForm.introductionIntention" placeholder="转介绍意向度" style="width:150px;height:50px">
        <el-option v-for="(item, index) in listeningIntentionalityPtions" :label="item.label" :key="item.value" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="开课时间" prop="curriculaTime">
      <el-date-picker
            v-model="dataForm.curriculaTime"
            type="datetime"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
    </el-form-item> -->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          studentId: '',
          studentStage: '',
          listeningIntentionality: '',
          sourceChannel: '',
          followStatus: '',
          followTime: '',
          consultant: '',
          classroomStatus: '',
          attendanceStatus: '',
          isUnsubscribe: '',
          auditionTime: '',
          appointmentPerson: '',
          appointmentTime: '',
          registrationIntention: '',
          studentType: '',
          studentStatus: '',
          coachTeacher: '',
          renewalIntention: '',
          introductionIntention: '',
          curriculaTime: '',
          delFlag: '',
          creator: '',
          createAt: '',
          updator: '',
          updateAt: ''
        },
        dataRule: {
          studentId: [
            { required: true, message: '学生姓名不能为空', trigger: 'blur' }
          ],
          listeningIntentionality: [
            { required: true, message: '试听意向度不能为空', trigger: 'blur' }
          ],
          sourceChannel: [
            { required: true, message: '来源渠道不能为空', trigger: 'blur' }
          ]
        },
        studentList: [],
        studentStagePtions: [{
          value: '0',
          label: '意向学员'
        }, {
          value: '1',
          label: '试听学员'
        }, {
          value: '2',
          label: '正式学员'
        }],
        classroomPtions: [{
          value: '0',
          label: '未开始'
        }, {
          value: '1',
          label: '正在进行'
        }, {
          value: '2',
          label: '已结束'
        }, {
          value: '3',
          label: '已取消'
        }],
        listeningIntentionalityPtions: [{
          value: '0',
          label: '未标记'
        }, {
          value: '1',
          label: '无'
        }, {
          value: '2',
          label: '低'
        }, {
          value: '3',
          label: '中'
        }, {
          value: '4',
          label: '高'
        }],
        sourceChannelPtions: [{
          value: '0',
          label: '无'
        }, {
          value: '1',
          label: '公告投放'
        }, {
          value: '2',
          label: '商场地推'
        }],
        followStatusPtions: [{
          value: '0',
          label: '未跟进'
        }, {
          value: '1',
          label: '跟进中'
        }],
        attendancePtions: [{
          value: '0',
          label: '缺席'
        }, {
          value: '1',
          label: '出席'
        }, {
          value: '2',
          label: '迟到'
        }],
        isUnsubscribePtions: [{
          value: '0',
          label: '未退订'
        }, {
          value: '1',
          label: '已退订'
        }],
        studentTypePtions: [{
          value: '0',
          label: '体验'
        }, {
          value: '1',
          label: 'VIP'
        }, {
          value: '2',
          label: 'SVIP'
        }],
        studentStatusPtions: [{
          value: '0',
          label: '未开课'
        }, {
          value: '1',
          label: '在读'
        }, {
          value: '2',
          label: '休学'
        }, {
          value: '3',
          label: '毕业'
        }, {
          value: '4',
          label: '退费'
        }]
      }
    },
    methods: {
      init (id, isConsultant) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/generator/studentmanage/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.studentId = data.studentManage.studentId
                /* this.dataForm.studentStage = data.studentManage.studentStage.toString()
                this.dataForm.listeningIntentionality = data.studentManage.listeningIntentionality.toString()
                this.dataForm.sourceChannel = data.studentManage.sourceChannel.toString()
                this.dataForm.followStatus = data.studentManage.followStatus.toString()
                this.dataForm.followTime = data.studentManage.followTime
                this.dataForm.consultant = data.studentManage.consultant
                this.dataForm.classroomStatus = data.studentManage.classroomStatus.toString()
                this.dataForm.attendanceStatus = data.studentManage.attendanceStatus.toString()
                this.dataForm.isUnsubscribe = data.studentManage.isUnsubscribe.toString()
                this.dataForm.auditionTime = data.studentManage.auditionTime
                this.dataForm.appointmentPerson = data.studentManage.appointmentPerson
                this.dataForm.appointmentTime = data.studentManage.appointmentTime
                this.dataForm.registrationIntention = data.studentManage.registrationIntention.toString()
                this.dataForm.studentType = data.studentManage.studentType.toString()
                this.dataForm.studentStatus = data.studentManage.studentStatus.toString() */
                this.dataForm.coachTeacher = data.studentManage.coachTeacher
                console.log(this.dataForm.coachTeacher)
                /* this.dataForm.renewalIntention = data.studentManage.renewalIntention.toString()
                this.dataForm.introductionIntention = data.studentManage.introductionIntention.toString()
                this.dataForm.curriculaTime = data.studentManage.curriculaTime
                this.dataForm.delFlag = data.studentManage.delFlag
                this.dataForm.creator = data.studentManage.creator
                this.dataForm.createAt = data.studentManage.createAt
                this.dataForm.updator = data.studentManage.updator
                this.dataForm.updateAt = data.studentManage.updateAt */
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/studentmanage/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'studentId': this.dataForm.studentId,
                'studentStage': this.dataForm.studentStage,
                'listeningIntentionality': this.dataForm.listeningIntentionality,
                'sourceChannel': this.dataForm.sourceChannel,
                'followStatus': this.dataForm.followStatus,
                'followTime': this.dataForm.followTime,
                'consultant': this.dataForm.consultant,
                'classroomStatus': this.dataForm.classroomStatus,
                'attendanceStatus': this.dataForm.attendanceStatus,
                'isUnsubscribe': this.dataForm.isUnsubscribe,
                'auditionTime': this.dataForm.auditionTime,
                'appointmentPerson': this.dataForm.appointmentPerson,
                'appointmentTime': this.dataForm.appointmentTime,
                'registrationIntention': this.dataForm.registrationIntention,
                'studentType': this.dataForm.studentType,
                'studentStatus': this.dataForm.studentStatus,
                'coachTeacher': this.dataForm.coachTeacher,
                'renewalIntention': this.dataForm.renewalIntention,
                'introductionIntention': this.dataForm.introductionIntention,
                'curriculaTime': this.dataForm.curriculaTime,
                'delFlag': this.dataForm.delFlag,
                'creator': this.dataForm.creator,
                'createAt': this.dataForm.createAt,
                'updator': this.dataForm.updator,
                'updateAt': this.dataForm.updateAt
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      // 获取学员
      getStudentList () {
        this.$http({
          url: this.$http.adornUrl('/business/student/getStudentList'),
          mothod: 'get',
          params: {}
        }).then(({data}) => {
          this.studentList = data.list
        })
      }
    }
  }
</script>
